<template>
  <div class="wrapper" ref="wrapper">
       <div class="content"><slot></slot></div>
  </div>
</template>
<script>
import BScroll from 'better-scroll'
export default {
  name: 'CodeScroll',
  components: { },
  directives: {  },
  props:{
    probeType:{
      type:Number,
      default:0
    },
    pullUpLoad:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
       scroll:null,
       message:'咻咻咻~~',
    };
  },
  mounted() {
    //1.创建BScroll实例对象
      // this.scroll=new BScroll(this.$refs.wrapper,{   
      //     click: true,
      //     pullUpLoad:this.pullUpLoad,
      //     observeDOM:true,
      //     probeType:this.probeType //0,1都不侦测实时位置  2手指滚动时侦测但不侦测惯性滑动    3都侦测
      // })
          //1.创建BScroll实例对象
          this.scroll=new BScroll(this.$refs.wrapper,{   
              click: true,
              pullUpLoad:this.pullUpLoad,
              observeDOM:true,
              probeType:this.probeType //0,1都不侦测实时位置  2手指滚动时侦测但不侦测惯性滑动    3都侦测
          })
          //console.log(this.scroll)
          //2.监听滚动位置
          this.scroll.on('scroll', (position) => {
              this.$emit('scroll-hd',position)
          })
           //3.上拉加载更多
          this.scroll.on('pullingUp', (position) => {
                // await fetchData()异步请求数据
                console.log('上拉加载更多~');
                this.$emit('pulling-up',position)
                //this.scroll.finishPullUp()
          })
  },
  methods: {
     scrollTop(x,y,time){
       this.scroll && this.scroll.scrollTo(x,y,time)
     },
     finishPullUp(){
      this.scroll && this.scroll.finishPullUp()
     },
    //  getScrollY(){
    //    return this.scroll ? this.scroll.y : 0
    //  }

  },
};
</script>